
#include <U8g2lib.h>
#include <Wire.h>
#include "BMP280.h"

U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

BMP280 bmp;

int Temperature;
int Pressure;
int Altitude;

void setup(){
  u8g2.begin();

  u8g2.enableUTF8Print();

    while (!bmp.begin()) {  
    Serial.println("Error initializing BMP280!");
    delay(1000);
  }

}

void loop(){
  Temperature = bmp.readTemperature();
  Pressure = bmp.readPressure()/100000;
  Altitude = bmp.readAltitude();
u8g2.firstPage();
  do
  {
    u8g2.setFont(u8g2_font_timR18_tf);
    u8g2.setFontPosTop();
    u8g2.setCursor(20,10);
    u8g2.print("BMP280");
    u8g2.setFont(u8g2_font_timR12_tf);
    u8g2.setFontPosTop();
    u8g2.drawFrame(4,4,120,56);
    u8g2.setCursor(15,40);
    u8g2.print(String(String("T:") + String(Temperature)) + String(".C"));
    u8g2.setCursor(70,40);
    u8g2.print(String(String("P:") + String(Pressure)) + String("kPa"));
  }while(u8g2.nextPage());
  delay(1000);
  u8g2.firstPage();
  do
  {
    u8g2.setFont(u8g2_font_timR18_tf);
    u8g2.setFontPosTop();
    u8g2.setCursor(25,10);
    u8g2.print("BMP280");
    u8g2.setFont(u8g2_font_timR12_tf);
    u8g2.setFontPosTop();
    u8g2.drawFrame(4,4,120,56);
    u8g2.setCursor(15,40);
    u8g2.print(String(String("A:") + String(Altitude)) + String("m"));
  }while(u8g2.nextPage());
  delay(1000);

}
